<?php
namespace Library\Redis;

class RedisManager
{
    private static $instance = null;

    private function __construct()
    {
        self::$instance = new \Redis();
        $config = require SF_LIBRARY_PATH . "RedisConfig.php";
        self::$instance->connect($config['host'], $config['port'], $config['timeout']);
        if (isset($config['password'])) {
            self::$instance->auth($config['password']);
        }
    }

    /**
     * 获取单例
     */
    public static function getRedis()
    {
        if (!self::$instance) {
            new self();
        }
        return self::$instance;
    }

    /**
     * 禁止clone
     */
    private function __clone() {}
}